#include <stdio.h>
#include <stdlib.h>

static int  index         = 0;
static char charsets[512] = {0};

static void
insert_char(unsigned char c)
{
	if (c == '\r') {
		charsets[index++] = '\\';
		charsets[index++] = 'r';
	} else {
		charsets[index++] = c;
	}
}

int
main(void)
{
        char          buffer[16] = {0};
        unsigned char c;

retry:
        system("clear");
        printf("%s\n", charsets);
        printf("(0/1, q 退出, c 清空)请输入: ");
        fgets(buffer, 15, stdin);
	if (buffer[0] == 'c') {
		index = 0;
		for (int i = 0; i < 512; ++i)
			charsets[i] = '\0';
	}

        if (buffer[0] == 'q')
                return 0;

        c = 0x0;
        for (int i = 0; i < 8; ++i)
                if (buffer[i] == '1')
                        c |= (0x80 >> i);
        insert_char(c);
        goto retry;

        return 0;
}
